#include "stdafx.h"
#include "winsock2.h"

#pragma comment(lib,"Ws2_32.lib")

#ifdef _MANAGED
#pragma managed(push, off)
#endif

BOOL APIENTRY DllMain( HMODULE hModule,
					  DWORD  ul_reason_for_call,
					  LPVOID lpReserved
					  )
{
	if(ul_reason_for_call == DLL_PROCESS_ATTACH)
	{
		//TRACE0("ISILNetSDK.DLL Initializing!\n");

		WORD	wVersionRequested;
		WSADATA wsaData;
		int		err;

		wVersionRequested = MAKEWORD( 2, 2 );

		err = WSAStartup( wVersionRequested, &wsaData );
		if ( err != 0 ) 
		{
			return FALSE;
		}
		if ( LOBYTE( wsaData.wVersion ) != 2 || HIBYTE( wsaData.wVersion ) != 2 ) 
		{			
			WSACleanup();

			return FALSE;
		}
	}
	else if (ul_reason_for_call == DLL_PROCESS_DETACH)
	{
		//TRACE0("ISILNetSDK.DLL Terminating!\n");
		// Terminate the library before destructors are called

		WSACleanup();
	}

	return TRUE;
}

#ifdef _MANAGED
#pragma managed(pop)
#endif